package a07_二叉树;

/**
 * <p>
 * a24_二叉搜索树的最小绝对差复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/25
 */
public class a24_二叉搜索树的最小绝对差复习2 {



    public int getMinimumDifference(TreeNode root) {

        traversal(root);
        return minDiffVal;
    }

    private int minDiffVal = Integer.MAX_VALUE;
    private TreeNode prevNode = null;
    private void traversal(TreeNode node){
        if (node == null) {
            return;
        }

        traversal(node.left);

        if (prevNode != null) {
            minDiffVal = Math.min(minDiffVal, node.val - prevNode.val);
        }

        prevNode = node;

        traversal(node.right);
    }
}
